/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.ember.ezsp.structure;

import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspDeserializer;
import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspSerializer;

/**
 * Class to implement the Ember Structure <b>EmberSourceRouteTableEntry</b>.
 * <p>
 * A source route table entry stores information about the next hop along the route to the
 * destination.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public class EmberSourceRouteTableEntry {

    /**
     * The node ID of the destination in that entry.
     * <p>
     * EZSP type is <i>EmberNodeId</i> - Java type is {@link int}
     */
    private int destination;

    /**
     * The closer node index for this source route table entry.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     */
    private int closerIndex;

    /**
     * Default Constructor
     */
    public EmberSourceRouteTableEntry() {
    }

    public EmberSourceRouteTableEntry(EzspDeserializer deserializer) {
        deserialize(deserializer);
    }

    /**
     * The node ID of the destination in that entry.
     * <p>
     * EZSP type is <i>EmberNodeId</i> - Java type is {@link int}
     *
     * @return the current destination as {@link int}
     */
    public int getDestination() {
        return destination;
    }

    /**
     * The node ID of the destination in that entry.
     *
     * @param destination the destination to set as {@link int}
     */
    public void setDestination(int destination) {
        this.destination = destination;
    }

    /**
     * The closer node index for this source route table entry.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     *
     * @return the current closerIndex as {@link int}
     */
    public int getCloserIndex() {
        return closerIndex;
    }

    /**
     * The closer node index for this source route table entry.
     *
     * @param closerIndex the closerIndex to set as {@link int}
     */
    public void setCloserIndex(int closerIndex) {
        this.closerIndex = closerIndex;
    }

    /**
     * Serialise the contents of the EZSP structure.
     *
     * @param serializer the {@link EzspSerializer} used to serialize
     */
    public int[] serialize(EzspSerializer serializer) {
        // Serialize the fields
        serializer.serializeUInt16(destination);
        serializer.serializeUInt8(closerIndex);
        return serializer.getPayload();
    }

    /**
     * Deserialise the contents of the EZSP structure.
     *
     * @param deserializer the {@link EzspDeserializer} used to deserialize
     */
    public void deserialize(EzspDeserializer deserializer) {
        // Deserialize the fields
        destination = deserializer.deserializeUInt16();
        closerIndex = deserializer.deserializeUInt8();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(79);
        builder.append("EmberSourceRouteTableEntry [destination=");
        builder.append(destination);
        builder.append(", closerIndex=");
        builder.append(closerIndex);
        builder.append(']');
        return builder.toString();
    }
}
